﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class TaiKhoanDAL
    {
        ConnectionData conn;

        public DataTable TaiKhoan_Check(TaiKhoanDTO TK_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 2;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "UserName";
            value[0] = TK_DTO.UserName;
            name[1] = "PassWord";
            value[1] = TK_DTO.PassWord;

            return conn.GetData("TAIKHOAN_CHECK", name, value, Nparameter);
        }

        public DataTable TaiKhoan_Get(TaiKhoanDTO TK_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "UserName";
            value[0] = TK_DTO.UserName;

            return conn.GetData("TAIKHOAN_GET", name, value, Nparameter);
        }

        public DataTable TaiKhoan_Load()
        {
            conn = new ConnectionData();

            return conn.GetData("TAIKHOAN_LOAD");
        }

        public DataTable TaiKhoan_LoadQuyen()
        {
            conn = new ConnectionData();

            return conn.GetData("PHANQUYEN_LOAD");
        }

        public int TaiKhoan_Insert(TaiKhoanDTO TK_DTO)
        {
            conn = new ConnectionData();
            int Nparameter = 3;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "UserName";
            value[0] = TK_DTO.UserName;
            name[1] = "PassWord";
            value[1] = TK_DTO.PassWord;
            name[2] = "MaQuyen";
            value[2] = TK_DTO.MaQuyen;

            return conn.UpdateData("TAIKHOAN_INSERT", name, value, Nparameter);
        }

        public int TaiKhoan_Update(TaiKhoanDTO TK_DTO)
        {
            conn = new ConnectionData();
            int Nparameter = 2;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "UserName";
            value[0] = TK_DTO.UserName;
            name[1] = "PassWord";
            value[1] = TK_DTO.PassWord;

            return conn.UpdateData("TAIKHOAN_UPDATE", name, value, Nparameter);
        }

        public int TaiKhoan_Delete(TaiKhoanDTO TK_DTO)
        {
            conn = new ConnectionData();
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "UserName";
            value[0] = TK_DTO.UserName;

            return conn.UpdateData("TAIKHOAN_DELETE", name, value, Nparameter);
        }
    }
}
